<template>
  <div class="order">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <el-row :gutter="25">
        <el-col :span="10" class="selectinput">
          <el-input
            v-model="params.query"
            placeholder="请输入内容"
            class="input-with-select"
            clearable
            @clear="clearquery"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="select"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table border :data="orderList" stripe style="width: 100%">
        <el-table-column label="#" type="index"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="120">
        </el-table-column>
        <!-- 0是未付款1已付款 -->
        <el-table-column label="是否付款" width="100">
          <template v-slot="scope">
            <!--     {{ typeof scope.row.pay_status }} -->
            <el-tag type="danger" v-if="scope.row.pay_status === '0'">
              未付款</el-tag
            >
            <el-tag type="success" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="80">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template v-slot="scope">
            {{ scope.row.create_time | startTime }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="showEdit"
            >
              编辑
            </el-button>
            <!--  删除 -->
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="showProgress"
            >
              定位
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.pagenum"
        :page-sizes="[5, 6, 8, 10]"
        :page-size="params.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      <!-- 编辑城市对话框 -->
      <el-dialog
        title="修改地址"
        :visible.sync="isshowEdit"
        width="30%"
        @close="closeEdit"
      >
        <el-form
          :model="editForm"
          :rules="editRules"
          ref="editRef"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item label="省/市/区/县" prop="address1">
            <el-cascader
              v-model="editForm.address1"
              :options="cityData"
              :props="props"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="address2">
            <el-input v-model="editForm.address2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="isshowEdit = false">取 消</el-button>
          <el-button type="primary" @click="isshowEdit = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 物流进度对话框 -->
      <el-dialog
        title="物流进度"
        :visible.sync="isshowProgress"
        width="30%"
        @close="closeProgress"
      >
        <el-timeline>
          <el-timeline-item
            v-for="(val, index) in progress"
            :key="index"
            :timestamp="progress.timestamp"
          >
            {{ val.content }}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import citydata from "./citydata";
import moment from "moment";
export default {
  name: "",
  components: {},
  data() {
    return {
      params: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      total: 0,
      orderList: [],
      isshowEdit: false,
      isshowProgress: false,
      editForm: {
        address1: [],
        address2: "",
      },
      editRules: {
        address1: [
          {
            type: "array",
            required: true,
            message: "选择地区",
            trigger: "change",
          },
        ],
        address2: [{ required: true, message: "选择地区", trigger: "blur" }],
      },
      cityData: citydata,
      props: { expandTrigger: "hover" },
      progress: [
        {
          content: "商家开始发货",
          timestamp: "2018-04-15",
        },
        {
          content: "揽货成功",
          timestamp: "2018-04-15",
        },
        {
          content: "发往北京集散中心",
          timestamp: "2018-04-16",
        },
        {
          content: "到达北京朝阳区",
          timestamp: "2018-04-18",
        },
        {
          content: "开始派送",
          timestamp: "2018-04-18",
        },
      ],
    };
  },
  methods: {
    async getOrder() {
      const { data: res } = await this.$request({
        url: "orders",
        params: this.params,
      });
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg);
      }
      this.total = res.data.total;
      this.orderList = res.data.goods;
      console.log(res);
    },
    clearquery() {
      this.getOrder();
    },
    handleSizeChange(newsize) {
      this.params.pagesize = newsize;
      this.getOrder();
    },
    handleCurrentChange(newpage) {
      this.params.pagenum = newpage;
      this.getOrder();
    },

    select() {
      this.getOrder();
    },
    showEdit() {
      this.isshowEdit = true;
    },
    closeEdit() {
      this.$refs.editRef.resetFields();
    },
    async showProgress() {
      /*  const { data: res } = await this.$request({
        url: "/kuaidi/1322456006161423151",
      });
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg);
      }
      console.log(res); */
      this.isshowProgress = true;
    },
    closeProgress() {},
  },
  created() {
    this.getOrder();
  },
  filters: {
    startTime(val) {
      return moment(val * 1000).format("YYYY-MM-DD hh:mm:ss");
    },
  },
};
</script>
<style lang="scss" scoped></style>
